<?php

use yii\db\Migration;

/**
 * Class m171127_025436_createTableCourseCount
 */
class m171127_025436_createTableCourseCount extends Migration
{
    /**
     * @inheritdoc
     */
    public function safeUp()
    {
        $tableOptions = null;
        if ($this->db->driverName === 'mysql') {
            // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
            $tableOptions = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=InnoDB';
        }

        $this->createTable('{{%course_count}}', [
            'id' => $this->primaryKey(),
            'course_id' => $this->string(50)->notNull()->defaultValue('')->comment('课程ID'),
            'grade' => $this->integer()->notNull()->defaultValue(0)->comment('评定等级'),
            'studynum' => $this->integer()->notNull()->defaultValue(0)->comment('学习人数'),
            'hit' => $this->integer()->notNull()->defaultValue(0)->comment('点击数'),
            'arinum' => $this->integer()->notNull()->defaultValue(0)->comment('评论数'),

            'created_at' => $this->integer()->notNull()->defaultValue(0)->comment('创建时间'),
            'updated_at' => $this->integer()->notNull()->defaultValue(0)->comment('更新时间'),
        ], $tableOptions);

        $this->addCommentOnTable('{{%course_count}}','课程信息表');
        $this->createIndex('course_count_course_id','{{%course_count}}','course_id');
    }

    /**
     * @inheritdoc
     */
    public function safeDown()
    {
        $this->dropTable('{{%course_count}}');
    }

    /*
    // Use up()/down() to run migration code without a transaction.
    public function up()
    {

    }

    public function down()
    {
        echo "m171127_025436_createTableCourseCount cannot be reverted.\n";

        return false;
    }
    */
}
